angular.module('myApp').controller('FormCtrl', function ($scope) {
    $scope.formFields = [{
        key: 'firstName',
        label: '活动名称',
        type: 'text',
        name: 'firstName',
        value: '',
        required: true,
        customValidationFunction: function (value) {
          // 自定义校验逻辑，例如用户名不能包含空格
          if (value && value.length == 2) {
            return '长度不能为2';
          }
          return ''; // 没有错误时返回空字符串
        }
      },
      {
        key: 'country',
        label: '活动区域',
        type: 'select',
        name: 'country',
        value: '',
        required: true,
        options: [{
            value: 'us',
            label: 'United States'
          },
          {
            value: 'ca',
            label: 'Canada'
          },
          {
            value: 'uk',
            label: 'United Kingdom'
          },
          {
            value: 'uk1',
            label: 'United Kingdom1'
          }
        ]
      },
      {
        key: 'dob',
        label: '活动时间',
        type: 'date',
        name: 'dob',
        value: null,
        required: true
      },
      {
        key: 'switch',
        label: '即时配送',
        type: 'switch',
        name: 'switch',
        use: {
          disabled: true,
        },
        value: null,
        required: false
      },
      {
        key: 'hobbies',
        label: '活动性质',
        type: 'checkbox',
        name: 'hobbies',
        value: [],
        required: true,
        options: [{
            value: 'reading',
            label: 'Reading',
            disabled: true
          },
          {
            value: 'traveling',
            label: 'Traveling'
          },
          {
            value: 'sports',
            label: 'Sports'
          }
        ]
      },
      {
        key: 'gender',
        label: '特殊资源',
        type: 'radio',
        name: 'gender',
        value: '',
        required: true,
        options: [{
            value: 'male',
            label: 'Male'
          },
          {
            value: 'female',
            label: 'Female'
          }
        ]
      },
    ];
    $scope.formData = {
      firstName: '',
      gender: '',
      hobbies: '',
      country: '',
      dob: null
    }
    $scope.onSelectChange = (select) => {
      console.log(select);
    }

    $scope.onSubmit = function(form) {
      console.log($scope.formFields,form);
    }
  })
  .directive('dynamicForm', dynamicForm)
  .directive('radioGroup', radioGroup)
  .directive('checkboxGroup', checkboxGroup)
  .directive('elSelect', elSelect);